package com.cs.service;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.query.Query;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.cs.dao.TeacherDaoImpl;
import com.cs.entity.Course;
import com.cs.entity.Grade;
import com.cs.entity.Student;
import com.cs.entity.Teacher;

@Service
@Transactional
public class TeacherServiceImpl {
	@Resource
	private TeacherDaoImpl tDaoImpl;
	
	//教师登录
	public Teacher teacherLogin(String tno,String tpassword){
		Teacher teacher = this.tDaoImpl.teacherLogin(tno, tpassword);
		if (teacher!=null) {
			return teacher;
		}else {
			return null;
		}
	}
	//查询个人信息（根据id）
	public Teacher findTeacherById(Integer id){
		Teacher teacher = this.tDaoImpl.findTeacherById(id);
		if (teacher!=null) {
			return teacher;
		}else {
			return null;
		}
	}
	//修改个人信息
	public boolean updateTeacher(Teacher teacher){
		return this.tDaoImpl.updateTeacher(teacher);
	}
	//添加课程
	public boolean addcourse(Course course){
		int addcourse = this.tDaoImpl.addcourse(course);
		if (addcourse>0) {
			return true;
		}
		return false;
	}
	//根据id查询教师开设的课程
	public List<Course> selectCourseByTid(Integer id){
		List<Course> courseByTid = this.tDaoImpl.selectCourseByTid(id);
		if (courseByTid!=null) {
			return courseByTid;
		}
		return null;
	}
	//根据学号查询学生
	public Student findStudentBySno(String sno){
		Student student = this.tDaoImpl.findStudentBySno(sno);
		return student;
	}
	//根据课程号查询课程
	public Course findCourseByCno(String cno){
		Course course = this.tDaoImpl.findCourseByCno(cno);
		return course;
	}
	//根据学号和课程号查询成绩
	public Grade findGradeBySnoandCno(String sno,String cno){
		return this.tDaoImpl.findGradeBySnoandCno(sno, cno);
	}
	//录入成绩（单个）
	public boolean addGrade(Grade grade){
		int a = this.tDaoImpl.addGrade(grade);
		if (a>0) {
			return true;
		}
		return false;
	}
	//根据专业查询学生(模糊查询）
	public List<Student> findStudentBySpecialities(String specialities){
		return this.tDaoImpl.findStudentBySpecialities(specialities);
	}
}
